package com.pet.system.task;

import com.pet.system.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class CleanUpTokenTask {

    @Autowired
    private TokenService tokenService;

    // 每天0:02:00 清理过期token
    @Async
    @Scheduled(cron = "0 2 0 * * ?")
    public void cleanUpToken() {
        tokenService.getLoginCacheMap().entrySet().removeIf(next -> next.getValue() < System.currentTimeMillis());
    }
}
